package com.shsxt.controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alipay.api.AlipayApiException;
import com.shsxt.service.OrderService;


@Controller
@RequestMapping("order")
public class OrderController  {
	
	
	@Autowired
	private OrderService orderService;
	
	
    @InitBinder
    public void initBinder(WebDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        dateFormat.setLenient(false);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));   //true:允许输入空值，false:不能为空值
    }
	

//---------------------------------------------------------------------
  //订单未完成(该用户未完成的订单)
    @RequestMapping(value="undone")
	public  @ResponseBody Map<String, Object> findUndoneOrder( String phoneNumber) throws ParseException {
    	Map<String, Object> undone = orderService.findUndoneOrder( phoneNumber);
		return undone;
	}
  //订单已完成(该用户已完成的订单)
    @RequestMapping(value="done")
	public  @ResponseBody Map<String, Object> findDoneOrder( String phoneNumber) throws ParseException {
    	Map<String, Object> undone = orderService.findDoneOrder(phoneNumber);
		return undone;
	}
  //订单已完成待评价
    @RequestMapping(value="done_unscore")
	public  @ResponseBody Map<String, Object> findUnscore( String phoneNumber) throws ParseException {
    	Map<String, Object> doneUnscore = orderService.findUnscore(phoneNumber);
		return doneUnscore;
	}
    //该用户全部订单
    @RequestMapping(value="all_order")
	public  @ResponseBody Map<String, Object> findAllOrder( String phoneNumber) throws ParseException {
    	Map<String, Object> allOrder = orderService.findAllOrder(phoneNumber);
		return allOrder;
	}
    //此订单详情(订单状态服务时间服务地点联系电话保洁时间和总价清洁剂时间和总价订单总价)
    @RequestMapping(value="detail")
	public  @ResponseBody Map<String, Object> findOrderMessage( String orderNumber,String type) throws ParseException {
    	List<Object>  orderDetails= orderService.findOrderMessage(orderNumber,type);
		Map<String, Object> map = new HashMap<String,Object>();
		map.put("0", orderDetails);
    	return map;
	}
    //取消订单
    @RequestMapping(value="cancelOrder")
	public  @ResponseBody Map<String, Object> cancelOrder( HttpServletRequest request,HttpServletResponse response,String orderNumber,String type) throws Exception {
    	Map<String, Object>  str= orderService.cancelOrder( request, response,orderNumber,type);
    	return str;
	}
    //删除订单
    @RequestMapping(value="deleteOrder")
	public  @ResponseBody Map<String, Object> deleteOrder( String orderNumber,String type) {
    	Map<String, Object>  str= orderService.deleteOrder(orderNumber,type);
    	return str;
	}
  //去评价
    @RequestMapping(value="toEvaluate")
	public  @ResponseBody Map<String, Object> toEvaluate( String orderNumber,String type) {
    	Map<String, Object>  str= orderService.toEvaluate(orderNumber,type);
    	return str;
	}
    //提交评价
    @RequestMapping(value="evaluate")
	public  @ResponseBody Map<String, Object> updateEvaluate( String orderNumber,String type,String evaluation,String score) {
    	Map<String, Object>  str= orderService.updateEvaluate(orderNumber,type,evaluation,score);
    	return str;
	}
  //查看评价
    @RequestMapping(value="findEvaluate")
	public  @ResponseBody Map<String, Object> findEvaluate( String orderNumber,String type) {
    	Map<String, Object>  str= orderService.findEvaluate(orderNumber,type);
    	return str;
	}
 /* //获取倒计时
    @RequestMapping(value="findDaojishi")
	public  @ResponseBody String findDaojishi( String orderNumber,String type) {
    	String  str= orderService.findDaojishi(orderNumber,type);
    	return str;
	}*/
   
   
		

	//---------------------------------------------------------------------
	

	
	
	
}
